local skynet = require "skynet"
local filelog = require "filelog"
local configdao = require "configdao"
local filename = "dnnodecmd.lua"
require "dnenum"

local dnnodecmd = {
	service = nil,
}

function dnnodecmd.init(service)
	if dnnodecmd.service == nil then
		dnnodecmd.service = service
	end
end

function dnnodecmd.start(conf)
	local server = dnnodecmd.service
	server:set_idle_table_pool(conf)
end

function dnnodecmd.reload()
	local server = dnnodecmd.service
	configdao.reload()
	server.CMD["reload_match_conf"]()
end

function dnnodecmd.delete_table(id, rids)
	local server = dnnodecmd.service
	return server:delete_table(id, rids)
end

function dnnodecmd.clear_ridinfo(ispass, rid, table_index, table_type)
	local server = dnnodecmd.service
	---if table_type == DNTableType.TABLE_TYPE_ZUANSI or table_type == DNTableType.TABLE_TYPE_FANGKA then
	server:unforward(rid, table_index)
	---elseif table_type == DNTableType.TABLE_TYPE_TRAIN then
		---server:unforward_train(rid)
	---end
end

function dnnodecmd.update_table_player(table_index, num, table_type, match_type, robot_num)
	local server = dnnodecmd.service
	server:update_table_player(table_index, num, table_type, match_type, robot_num)
end

function dnnodecmd.get_gamenode_data()
	local server = dnnodecmd.service
	return server.table_service_map
end

function dnnodecmd.set_gameend_flag()
	---filelog.sys_error("-----dnnodecmd.set_gameend_flag-----")
	local server = dnnodecmd.service
	server:set_server_flag(true)
	---通知robotmgr回写robotinfo
	skynet.send(".robotmgr", "lua", "game_end")
end

function dnnodecmd.set_tableend_flag(table_code)
	---filelog.sys_error("-----dnnodecmd--set_tableend_flag-----")
	local server = dnnodecmd.service
	local table_index = server.code_to_index[table_code]
	if table_index == nil then return false end
	local table_service_obj = server.index_to_table[table_index]
	if table_service_obj == nil then return false end
	local ok, result = pcall(skynet.call, table_service_obj.table_service, "lua", "update_stop_server", true)
end

function dnnodecmd.clear_player_state(rid)
	local server = dnnodecmd.service
	server:clear_player_state(rid)
end

function dnnodecmd.get_role_data(zeroflag, rid)
	local server = dnnodecmd.service
	return server:get_role_data(rid)
end

return dnnodecmd